<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setCharacterEncoding("GB2312");
	String roleId = request.getParameter("roleId");
	
	if (roleId != null) {
		roleId = new String(roleId.getBytes("iso-8859-1"), "GB2312");
	} else {
		roleId = "";
	}
	String userList = request.getParameter("userList");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>角色</title>
<script src='/HTOA/js/miniui/scripts/boot.js' type='text/javascript'></script>
<style type='text/css'>
html,body,form {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
}
</style>
<script language="JavaScript" type="text/javascript">
	var gArrListBox = [],addUserId="",addUserList="";
	$(document).ready(
			function() {
				$.ajax({
					url : "/HTOA/admin/findAllRoleTypeJson.action",
					cache : false,
					dataType : "text",
					success : function(data) {
						mini.get("ListCategory_P").setData(data);
						mini.get("ListCategory_P").on("itemclick", function(e) {
							var obj = e.sender;
							$("[name=ListCategory]").val(obj.getValue());
						})
						//mini.get("ListCategory_P").setValue("");
					}
				})

			})
	function goSubmit() {
		var strRoleName = mini.getbyName("role.roleName").getValue();
		if (strRoleName == "") {
			alert("请填写角色名称！");
			return false;
		} else {
			if (strRoleName.length > 40) {
				alert("角色名称长度不能超过40！");
				return false;
			}
		}
		if (confirm("您确信需要保存吗？")) {
			document.forms[0].Members.value = gArrListBox.join(",");
			document.forms[0].submit();
		}
	}
	/*
	 描述：增加人员
	 */
	function goAdd(e) {
		var Name = e.node.text;
		addUserId = e.node.id;
		if(e.node.type == "user"){
			if ($.inArray(addUserId,gArrListBox) < 0) {
				gListBox.addItem({
					id : addUserId,
					text : Name
				});
				gArrListBox.push(addUserId);
			} else {
				alert(Name + " 已存在！");
			}
		}
		
	}
	/*
	 描述：删除人员
	 */
	function goDel(e) {
		var userId = e.item.id;
		if ($.inArray(userId,gArrListBox) > -1) {
			//从已选择数组中移出所选项
			gArrListBox = $.grep(gArrListBox, function(n,i) {
				return n == userId;
			}, true);
			//从列表中移出所选项
			gListBox.removeItem(e.item);
		}
		
	}

	/*
	描述：关闭窗口
	 */
	function CloseWindow() {
		if (window.CloseOwnerWindow) {
			return window.CloseOwnerWindow();
		} else {
			window.close();
		}
	}

</script>
</head>
<body text="#000000" bgcolor="#FFFFFF">

	<form method="post" action="/HTOA/admin/saveUserToRole.action"
		name="_fmRole">
		<input type="hidden" name="__Click" value="0">

		<table style="display:none" border="1">
			<tr valign="top">
				<td width="161"><img width="1" height="1"
					src="/icons/ecblank.gif" border="0" alt=""></td>
				<td width="232">Group</td>
			</tr>

			<tr valign="top">
				<td width="161"><img width="1" height="1"
					src="/icons/ecblank.gif" border="0" alt=""></td>
				<td width="232"><input name="OldRoleName" value=""></td>
			</tr>

			<tr valign="top">
				<td width="161"><img width="1" height="1"
					src="/icons/ecblank.gif" border="0" alt=""></td>
				<td width="232"><input name="Members" value=""></td>
			</tr>
		</table>
		<table border="0" cellpadding="1" cellspacing="4"
			style="width:98%;height:100%;margin:0 auto">
			<tr>
				<td align="right" style="width:85px">角色名称：</td>
				<td style="width:285px"><input name="role.roleName"
					value="" class="mini-textbox" style="width:100%"></td>
			</tr>
			<tr>
				<td align="right" style="width:85px">角色分类：</td>
				<td style="width:285px">
					<div id="ListCategory_P" class="mini-combobox" style="width:100%"
						popupWidth="250" textField="text" valueField="id"
						multiSelect="true" showClose="true" oncloseclick="onCloseClick">
						<div property="columns">
							<div header="人员" field="text"></div>
						</div>
					</div> <input name="ListCategory" value="" style="display:none">
					<input name="role.uuid" value="" style="display:none"/>
					<input name="userList" id="userList" style="display:none"/>
				</td>
			</tr>
			<tr>
				<td align="right" style="width:85px">描述：</td>
				<td><input name="role.roleDescribe" value=""
					class="mini-textbox" style="width:100%"></td>
			</tr>
			<tr>
				<td colspan=2 valign="top" align="center">
					<table border="0" cellpadding="0" cellspacing="4"
						style="width:100%">
						<tr>
							<td style="width:50%" valign="top">
								<div style="border:1px solid #808080;height:352px;width:100%;">
									<ul id="OrgTree" class="mini-tree" onnodedblclick="goAdd"
										textField="text" height="100%">
									</ul>
								</div>
							</td>
							<td style="width:50%" valign="top">
								<div id="ListBox" class="mini-listbox"
									style="width:100%;height:354px;" 
									onitemdblclick="goDel" valueField="id" textField="text"></div>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<script type="text/javascript">
			mini.parse();
			var gListBox = mini.get("ListBox");
			var gOrgTree = mini.get("OrgTree");
			//异步加载数据，去掉数据最前端的逗号，使得tree数据格式正确。
			$.ajax({
				url : "/HTOA/admin/findOrgTree.action",
				cache : false,
				dataType : "text",
				success : function(data) {
					var MenuText = mini.decode(data);
					if (data.indexOf(",") > -1) {
						gOrgTree.loadList(MenuText, "id", "pid");
						gOrgTree.expandLevel(0);
					} else {
						gOrgTree.loadList([], "id", "pid");
					}
				}
			});
		</script>
	</form>
</body>
</html>
